Copyright ã1995 by NeXT Computer, Inc.  All Rights Reserved.

IXComparatorSetting

Adopted By:	IXBTree

Declared In:	btree/protocols.h

Protocol Description

The IXComparatorSetting protocol is implemented by objects that compare data elements of unknown type using a comparison function provided by the client.  This gives the object great flexibility in handling an open set of data types.  A comparator function as used by this protocol is of type IXComparator *, which has the form:

typedef int IXComparator(const void *data1, unsigned short length1,
    const void *data2, unsigned short length2, const void *context);

where data1 is a pointer to any block of length1 bytes, data2 is a pointer to a block of length2 bytes, and context is a pointer to blind data which  may be used by the comparator function (for an example of this, see IXFormatComparator() in the ªFunctionsº section, later in this chapter).  The comparator function returns a number less than 0 if data1 is considered less then data2, greater than 0 if data1 is considered greater than data2, and equal to zero if data1 and data2 are considered equal.

There are several standard comparator functions defined by the Indexing Kit.  See the ªFunctionsº section for the full listing.

Comparator functions are intended to compare serial arrays of data, particularly keys in an associative store (like an IXBTree or a hash table).  A key is always serialized when placed in a store; the resulting representation doesn't contain pointers.  A comparator function like IXCompareStrings() doesn't expect to receive arrays of character pointers; rather, it expects data1 and data2 to be serial arrays containing strings separated by embedded nulls.

Instance Methods

getComparator:andContext:

- getComparator:(IXComparator **)aComparator andContext:(const void **)aContext

Returns by reference the function used to compare data elements, and the context associated with the function.  aContext is blind data that the object passes to the comparator function as the context argument.  Returns self.

setComparator:andContext:

- setComparator:(IXComparator *)aComparator andContext:(const void *)aContext

Sets the function used to compare data elements, and the context associated with the function.  aContext is blind data that the object passes to its comparator function as the context argument whenever it calls that function.  Returns self.